using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AlphaWebsite.Models;

namespace AlphaWebsite.Controllers
{   
    public class DefaultBudgetItemsController : Controller
    {
		private readonly IBudgetCategoryRepository budgetcategoryRepository;
		private readonly IDefaultBudgetItemsRepository defaultbudgetitemsRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public DefaultBudgetItemsController() : this(new BudgetCategoryRepository(), new DefaultBudgetItemsRepository())
        {
        }

        public DefaultBudgetItemsController(IBudgetCategoryRepository budgetcategoryRepository, IDefaultBudgetItemsRepository defaultbudgetitemsRepository)
        {
			this.budgetcategoryRepository = budgetcategoryRepository;
			this.defaultbudgetitemsRepository = defaultbudgetitemsRepository;
        }

        //
        // GET: /DefaultBudgetItems/

        public ViewResult Index()
        {
            return View(defaultbudgetitemsRepository.AllIncluding(defaultbudgetitems => defaultbudgetitems.BudgetCategory));
        }

        //
        // GET: /DefaultBudgetItems/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(defaultbudgetitemsRepository.Find(id));
        }

        //
        // GET: /DefaultBudgetItems/Create

        public ActionResult Create()
        {
			ViewBag.PossibleBudgetCategories = budgetcategoryRepository.All;
            return View();
        } 

        //
        // POST: /DefaultBudgetItems/Create

        [HttpPost]
        public ActionResult Create(DefaultBudgetItems defaultbudgetitems)
        {
            if (ModelState.IsValid) {
                defaultbudgetitemsRepository.InsertOrUpdate(defaultbudgetitems);
                defaultbudgetitemsRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleBudgetCategories = budgetcategoryRepository.All;
				return View();
			}
        }
        
        //
        // GET: /DefaultBudgetItems/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossibleBudgetCategories = budgetcategoryRepository.All;
             return View(defaultbudgetitemsRepository.Find(id));
        }

        //
        // POST: /DefaultBudgetItems/Edit/5

        [HttpPost]
        public ActionResult Edit(DefaultBudgetItems defaultbudgetitems)
        {
            if (ModelState.IsValid) {
                defaultbudgetitemsRepository.InsertOrUpdate(defaultbudgetitems);
                defaultbudgetitemsRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleBudgetCategories = budgetcategoryRepository.All;
				return View();
			}
        }

        //
        // GET: /DefaultBudgetItems/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(defaultbudgetitemsRepository.Find(id));
        }

        //
        // POST: /DefaultBudgetItems/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            defaultbudgetitemsRepository.Delete(id);
            defaultbudgetitemsRepository.Save();

            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing) {
                budgetcategoryRepository.Dispose();
                defaultbudgetitemsRepository.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}

